<?php
    error_reporting(E_ALL & ~E_DEPRECATED);    
    require_once("condb.php");
    require_once("functions_sms_kute.php");  
                     
    $output = array();
    
    $info = isset($_GET["info"]) ? $_GET["info"] : "";
    if(empty($info)){
        $output["status"] = 5;
        $output["msg"] = "Invalid Request";
    } else {
        $info = urldecode(base64_decode($info));
        parse_str($info, $request);    
        
        $token = isset($request["token"]) ? cleanQuery($request["token"]) : "";
        if($token=="SmsKUteTAovieC@)!#"){
            $refCode = isset($request["refCode"]) ? cleanQuery($request["refCode"]) : "";            
            $list_sms_id = isset($request["list_sms_id"]) ? cleanQuery($request["list_sms_id"]) : "";
             
            if(!empty($refCode) && !empty($list_sms_id)){
                /* lấy userid */
                $user = getUser($refCode);
                
                if(!empty($user)){
                    
                    /* Lấy các sms kute */
//                    if($list_sms_id=="1036,1037,1038,1039,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055"){
                        $sms = getSms($list_sms_id);    
                    //} else {
//                        $sms = getSms($user["id"], $list_sms_id);
//                    }
                    
                    $contents = array();
                    foreach($sms as $row){
                        $content["id"] = $row["id"]; 
                        $content["title"] = $row["title"]; 
                        $content["content"] = $row["content"]; 
                        $content["image"] = getImage($row["id"] . "_app.jpg", "sms_cute", $row["create_date"]); 
                        
                        $contents[] = $content;
                    }
                    
                    $output["status"] = 1;
                    $output["msg"] = "Success Request";
                } else {
                    $output["status"] = 2;
                    $output["msg"] = "Refcode khong ton tai trong he thong";        
                }
                
            } else {
                $output["status"] = 3;
                $output["msg"] = "Cac tham so khong hop le";    
            }
        } else {
            $output["status"] = 4;
            $output["msg"] = "Sai token";    
        }
    }
    $output["sms"] = isset($contents) ? $contents : array();    
    
    echo json_encode($output);
?>
